<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
    
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    Advanced_JS_one.md |  Small Bridge
  </title>
  <meta name="generator" content="hexo-theme-yilia-plus">
  
  <link rel="shortcut icon" href="/favicon.ico" />
  
  
<link rel="stylesheet" href="/css/main.css">

  
  <script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>
  
  

  

<link rel="alternate" href="/atom.xml" title="Small Bridge" type="application/atom+xml">
</head>

</html>

<body>
  <div id="app">
    <main class="content">
      <section class="outer">
  <article id="post-Advanced-JS-one-md" class="article article-type-post" itemscope
  itemprop="blogPost" data-scroll-reveal>

  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  Advanced_JS_one.md
</h1>
  

    </header>
    

    
    <div class="article-meta">
      <a href="/2020/06/13/Advanced-JS-one-md/" class="article-date">
  <time datetime="2020-06-13T13:38:11.000Z" itemprop="datePublished">2020-06-13</time>
</a>
      
  <div class="article-category">
    <a class="article-category-link" href="/categories/JavaScript/">JavaScript</a>
  </div>

      
      
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> 字数统计:</span>
            <span class="post-count">2.2k字</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> 阅读时长≈</span>
            <span class="post-count">8分钟</span>
        </span>
    </span>
</div>

      
    </div>
    

    
    
    <div class="tocbot"></div>





    

    
    <div class="article-entry" itemprop="articleBody">
      


      

      
      <p>@<a href="JS高级">TOC</a></p>
<h1 id="基础总结深入"><a href="#基础总结深入" class="headerlink" title="基础总结深入"></a>基础总结深入</h1><a id="more"></a>
<ol>
<li>数据类型<br>a.分类<br>基本类型(又称值类型):<br> String    (任意字符串)<br> Number (任意数字)<br> boolean (true/false)<br> undefined (undefined)<br> null  (null)<br>对象类型(又称引用类型):<br> Object    (任意对象)<br> Function (一种特殊的对象，可以执行)<br> Array       (一种特殊的对象，数值下标，内部数据有序)<br>b.判断<br> typeof (返回数据类型的<code>字符串表达</code>)<br> 可以判断：undefined/数值/字符串/布尔值/function<br> 不能判断：null与Object   Object与Array<br> instanceof(判断对象的具体类型，返回<code>布尔值</code>)<br> 绝对等于符号(===)<br> 可以判断undefined，null<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br></pre></td><td class="code"><pre><span class="line">&lt;script type=<span class="string">"text/javascript"</span>&gt;</span><br><span class="line">		<span class="comment">//1.基本</span></span><br><span class="line">		<span class="keyword">var</span> a;</span><br><span class="line">		<span class="built_in">console</span>.log(a,<span class="keyword">typeof</span> a,<span class="keyword">typeof</span> a === <span class="string">'undefined'</span>,a === <span class="literal">undefined</span>);<span class="comment">//undefined 'undefined' true true</span></span><br><span class="line">		<span class="built_in">console</span>.log(<span class="literal">undefined</span> === <span class="string">'undefined'</span>);<span class="comment">//false</span></span><br><span class="line">		</span><br><span class="line">		a = <span class="number">4</span>;</span><br><span class="line">		<span class="built_in">console</span>.log(<span class="keyword">typeof</span> a === <span class="string">'number'</span>); <span class="comment">//true</span></span><br><span class="line">		a = <span class="string">'cxq'</span>;</span><br><span class="line">		<span class="built_in">console</span>.log(<span class="keyword">typeof</span> a === <span class="string">'string'</span>); <span class="comment">//true</span></span><br><span class="line">		a = <span class="literal">true</span>;</span><br><span class="line">		<span class="built_in">console</span>.log(<span class="keyword">typeof</span> a === <span class="string">'boolean'</span>); <span class="comment">//true</span></span><br><span class="line">		a = <span class="literal">null</span>;</span><br><span class="line">		<span class="built_in">console</span>.log(<span class="keyword">typeof</span> a,a === <span class="literal">null</span>); <span class="comment">//'object' true</span></span><br><span class="line">		</span><br><span class="line">		<span class="comment">//2.对象</span></span><br><span class="line">		<span class="keyword">var</span> b1 = &#123;</span><br><span class="line">			b2: [<span class="number">1</span>,<span class="string">'abc'</span>,<span class="built_in">console</span>.log],</span><br><span class="line">			b3: <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">				<span class="built_in">console</span>.log(<span class="string">'b3'</span>);</span><br><span class="line">				<span class="keyword">return</span> <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">					<span class="keyword">return</span> <span class="string">'cxq'</span>;</span><br><span class="line">				&#125;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">		</span><br><span class="line">		<span class="built_in">console</span>.log(b1 <span class="keyword">instanceof</span> <span class="built_in">Object</span>,b1 <span class="keyword">instanceof</span> <span class="built_in">Array</span>); <span class="comment">//instance实例的意思 true false</span></span><br><span class="line">		<span class="built_in">console</span>.log(b1.b2 <span class="keyword">instanceof</span> <span class="built_in">Array</span>,b1[<span class="string">"b2"</span>] <span class="keyword">instanceof</span> <span class="built_in">Object</span>);</span><br><span class="line">		<span class="built_in">console</span>.log(b1.b3 <span class="keyword">instanceof</span> <span class="built_in">Function</span>,b1.b3 <span class="keyword">instanceof</span> <span class="built_in">Object</span>);</span><br><span class="line">		</span><br><span class="line">		<span class="built_in">console</span>.log(<span class="keyword">typeof</span> b1.b2,<span class="string">'-----'</span>); <span class="comment">//'object'</span></span><br><span class="line">		</span><br><span class="line">		<span class="built_in">console</span>.log(<span class="keyword">typeof</span> b1.b3 === <span class="string">'function'</span>); <span class="comment">//true</span></span><br><span class="line">		</span><br><span class="line">		<span class="built_in">console</span>.log(<span class="keyword">typeof</span> b1.b2[<span class="number">2</span>] === <span class="string">'function'</span>); <span class="comment">//true</span></span><br><span class="line">		b1.b2[<span class="number">2</span>](<span class="number">4</span>);</span><br><span class="line">		<span class="built_in">console</span>.log(b1.b3()());</span><br><span class="line">		</span><br><span class="line">	&lt;<span class="regexp">/script&gt;</span></span><br><span class="line"><span class="regexp">```	</span></span><br><span class="line"><span class="regexp">c.相关问题</span></span><br><span class="line"><span class="regexp">undefined和null的区别？</span></span><br><span class="line"><span class="regexp">undefined代表定义了未赋值，null代表定义并赋值了，只是值为null</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">什么时候给变量赋值为null？</span></span><br><span class="line"><span class="regexp">初始赋值：表示将要赋值为对象</span></span><br><span class="line"><span class="regexp">结束前赋值：让对象成为垃圾对象，进而被回收</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">严格区分变量类型与数据类型？</span></span><br><span class="line"><span class="regexp">变量的类型实质上指的是变量内存值的类型，基本类型保存的就是基本类型的数据，引用类型保存的是地址值。JS是弱类型的语言，变量本身是没有类型的，我们所讨论的类型其实是变量所保存的数据的类型，只是平时不加区分就是说的变量的类型</span></span><br><span class="line"><span class="regexp">```javascript</span></span><br><span class="line"><span class="regexp">&lt;script type="text/</span>javascript<span class="string">"&gt;</span></span><br><span class="line"><span class="string">		//实例：实例对象</span></span><br><span class="line"><span class="string">		//类型：类型对象</span></span><br><span class="line"><span class="string">		function Person(name,age)&#123;  //构造函数 类型</span></span><br><span class="line"><span class="string">			this.name = name;</span></span><br><span class="line"><span class="string">			this.age = age;</span></span><br><span class="line"><span class="string">		&#125;</span></span><br><span class="line"><span class="string">		var p = new Person('tom',12); //根据类型创建的实例对象</span></span><br><span class="line"><span class="string">		</span></span><br><span class="line"><span class="string">		//Person('jack',13);</span></span><br><span class="line"><span class="string">		</span></span><br><span class="line"><span class="string">		var a;</span></span><br><span class="line"><span class="string">		console.log(a); //undefined</span></span><br><span class="line"><span class="string">		a = null;</span></span><br><span class="line"><span class="string">		console.log(a); //null</span></span><br><span class="line"><span class="string">		</span></span><br><span class="line"><span class="string">		var b = null;  //初始赋值为null 表明将要赋值为对象</span></span><br><span class="line"><span class="string">		b = ['1','2']; //确定对象就赋值</span></span><br><span class="line"><span class="string">		b = null;      //让b指向的对象成为垃圾对象(被垃圾回收器回收)</span></span><br><span class="line"><span class="string">		//b = 2;  同样可以切断那条线，但是没有意义</span></span><br><span class="line"><span class="string">	&lt;/script&gt;</span></span><br></pre></td></tr></table></figure>
d.数据_变量_内存<br>什么是数据？<br>存储在内存中代表特定信息的载体，本质上是010101….,特点可传递，可运算</li>
</ol>
<p>什么是变量？<br>由变量名和变量值组成的可变化的量。每个变量都对应一块小内存，变量名用来查找对应的内容，变量值就是内存中保存的数据</p>
<p>什么是内存？<br>内存条通电后产生的可存储数据的临时空间。一块小内存有2个数据：内存存储的数据、地址值<br>内存的分类<br>栈：存储全局变量和局部变量<br>堆：存储对象</p>
<p>三者之间的关系？<br>内存是用来存储数据的空间，变量是内存的标识，我们通过变量找到对应的内存，进而操作内存中的数据<br>e.相关问题<br>关于赋值和内存的问题：var a = xxx,a内存中到底保存的是什么？<br>xxx是基本数据，保存的就是这个数据<br>xxx是对象，保存的是对象的地址值<br>xxx是变量，保存的是变量的内存内容(可能是基本数据，也可能是地址值)</p>
<p>关于引用变量赋值问题<br>n个引用变量指向同一个对象，通过某个变量修改对象内部数据，其他所有变量看到的是修改之后的数据<br>2个引用变量指向同一个对象,让其中一个引用变量指向另一个对象，另一个引用变量依然指向前一个对象</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">&lt;script type=<span class="string">"text/javascript"</span>&gt;</span><br><span class="line">		<span class="keyword">var</span> obj1 = &#123;<span class="attr">name</span>: <span class="string">'Tom'</span>&#125;;</span><br><span class="line">		<span class="keyword">var</span> obj2 = obj1;</span><br><span class="line">		obj2.age = <span class="string">'12'</span>;</span><br><span class="line">		<span class="built_in">console</span>.log(obj1.age); <span class="comment">// '12'</span></span><br><span class="line">		</span><br><span class="line">		<span class="function"><span class="keyword">function</span> <span class="title">fn</span>(<span class="params">obj</span>)</span>&#123;</span><br><span class="line">			obj.name = <span class="string">'A'</span>;</span><br><span class="line">		&#125;</span><br><span class="line">		</span><br><span class="line">		fn(obj1);</span><br><span class="line">		</span><br><span class="line">		<span class="built_in">console</span>.log(obj2.name) <span class="comment">//'A'</span></span><br><span class="line">		</span><br><span class="line">		<span class="keyword">var</span> a = &#123;<span class="attr">age</span>: <span class="number">12</span>&#125;;</span><br><span class="line">		<span class="keyword">var</span> b = a;</span><br><span class="line">		a = &#123;<span class="attr">name</span>: <span class="string">'Tom'</span>,<span class="attr">age</span>: <span class="number">13</span>&#125;;</span><br><span class="line">		b.age = <span class="number">14</span>;</span><br><span class="line">		<span class="built_in">console</span>.log(b.age,a.name,a.age); <span class="comment">// 14 'Tom' 13</span></span><br><span class="line">		</span><br><span class="line">		<span class="comment">//执行形参赋值 obj = a,这是两个同时指向了对象&#123;age:13,name:'Tom'&#125;</span></span><br><span class="line">		<span class="comment">//然后执行obj = &#123;age: 15&#125;注意是等于，不是.,就是obj指向了新的对象&#123;age: 15&#125;</span></span><br><span class="line">		<span class="comment">//不再指向a指向的对象，两个互不干涉</span></span><br><span class="line">		<span class="function"><span class="keyword">function</span> <span class="title">fn2</span>(<span class="params">obj</span>)</span>&#123;</span><br><span class="line">			obj = &#123;<span class="attr">age</span>: <span class="number">15</span>&#125;;</span><br><span class="line">		&#125;</span><br><span class="line">		</span><br><span class="line">		fn2(a);</span><br><span class="line">		<span class="built_in">console</span>.log(a.age); <span class="comment">//13</span></span><br><span class="line">	&lt;<span class="regexp">/script&gt;</span></span><br></pre></td></tr></table></figure>
<p>在JS调用函数时传递变量参数，是值传递还是引用传递？<br>理解1：都是值传递，传递的是基本数据类型的值或者对象的地址值<br>理解2：可能是值传递，也可能是引用传递，基本数据类型就是值传递，对象类型是引用传递，传递的是地址值</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">&lt;script type=<span class="string">"text/javascript"</span>&gt;</span><br><span class="line">		<span class="keyword">var</span> a = <span class="number">3</span>;</span><br><span class="line">		<span class="comment">//值传递，相当于执行 a = 3,先读取全局变量a的值3，再赋值给形参a</span></span><br><span class="line">		<span class="comment">//传递的参数是3，跟全局变量a没有关系了，所以全局a还是3，为什么要用两个a嘛</span></span><br><span class="line">		<span class="comment">//我故意混淆的</span></span><br><span class="line">		<span class="function"><span class="keyword">function</span> <span class="title">fn</span>(<span class="params">a</span>)</span>&#123;</span><br><span class="line">			a = a + <span class="number">1</span>;</span><br><span class="line">		&#125;</span><br><span class="line">		fn(a);</span><br><span class="line">		<span class="built_in">console</span>.log(a); <span class="comment">//3</span></span><br><span class="line">	&lt;<span class="regexp">/script&gt;</span></span><br></pre></td></tr></table></figure>
<p>JS引擎如何管理内存？<br>内存生命周期：<br>分配小内存空间—&gt;得到它的使用权—&gt;存储数据,可以反复进行操作—&gt;释放小内存空间<br>释放内存：<br>局部变量：函数执行完后自动释放<br>对象：成为垃圾对象—-&gt;垃圾回收器回收</p>
<p>f.对象<br>什么是对象？<br>多个数据的封装体<br>用来保存多个数据的容器<br>一个对象代表现实中的一个事物</p>
<p>为什么要用对象？<br>统一管理多个数据</p>
<p>对象的组成？<br>属性：属性名(字符串)加属性值(任意值)组成<br>方法：一种特别的属性(属性值是函数)</p>
<p>如何访问对象内部数据？<br>对象名.属性名<br>对象名[‘属性名’]</p>
<p>什么时候必须使用对象名[‘属性名’]的方式？<br>属性名包括特殊字符:-,空格<br>属性名不确定的时候</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">&lt;script type=<span class="string">"text/javascript"</span>&gt;</span><br><span class="line">		<span class="keyword">var</span> p =&#123;&#125;;</span><br><span class="line">		<span class="comment">//p.content-type = 'text/json';  报错</span></span><br><span class="line">		p[<span class="string">'content-type'</span>] = <span class="string">'text/json'</span>;</span><br><span class="line">		<span class="built_in">console</span>.log(p[<span class="string">'content-type'</span>]);</span><br><span class="line">		</span><br><span class="line">		<span class="keyword">var</span> propName = <span class="string">'myAge'</span>;</span><br><span class="line">		<span class="keyword">var</span> value = <span class="number">18</span>;</span><br><span class="line">		p[propName] = value;</span><br><span class="line">		<span class="built_in">console</span>.log(p[propName]);</span><br><span class="line">	&lt;<span class="regexp">/script&gt;</span></span><br></pre></td></tr></table></figure>

<p>g.函数<br>什么是函数？<br>实现特定功能的n条语句的封装体，只有函数是可以执行的，其他类型的数据不能执行</p>
<p>为什么要用函数？<br>提高代码复用，便于阅读复用</p>
<p>如何定义函数？<br>函数声明<br>表达式</p>
<p>如何调用(执行)函数？<br>test() 直接调用<br>obj.test() 通过对象调用<br>new test() 构造函数调用<br>test.apply(obj)/test.call(obj) 在指定对象上调用,临时让test成为obj的方法进行调用</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">&lt;script type=<span class="string">"text/javascript"</span>&gt;</span><br><span class="line">		<span class="function"><span class="keyword">function</span> <span class="title">fn</span>(<span class="params"></span>)</span>&#123; <span class="comment">//函数声明</span></span><br><span class="line">			</span><br><span class="line">		&#125;</span><br><span class="line">		</span><br><span class="line">		<span class="keyword">var</span> fn1 = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;&#125;  <span class="comment">//表达式声明</span></span><br><span class="line">		</span><br><span class="line">		<span class="function"><span class="keyword">function</span> <span class="title">fn2</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">			<span class="keyword">this</span>.xxx = <span class="string">'cxq'</span>;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">var</span> obj = &#123;&#125;;</span><br><span class="line">		<span class="comment">//obj.fn2()  不能直接调用，因为根本就没有</span></span><br><span class="line">		fn2.call(obj);  <span class="comment">//可以让函数成为指定任意对象的方法进行调用</span></span><br><span class="line">		<span class="built_in">console</span>.log(obj.xxx);</span><br><span class="line">	&lt;<span class="regexp">/script&gt;</span></span><br></pre></td></tr></table></figure>

<p>回调函数<br>什么是回调函数？<br>你定义了<br>你没有调<br>但最终它执行了</p>
<p>常见的回调函数<br>dom事件回调函数<br>定时器回调函数<br>ajax请求回调函数<br>生命周期回调函数</p>
<p>IIFE(Immediately-Invoked Function Expression) 立即执行函数表达式，又称匿名函数自调用<br>作用<br>隐藏实现<br>不会污染外部(全局)命名空间<br>用来编写JS模块</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">&lt;script type=<span class="string">"text/javascript"</span>&gt;</span><br><span class="line">		(<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">			<span class="keyword">var</span> a = <span class="number">3</span>;</span><br><span class="line">			<span class="built_in">console</span>.log(a + <span class="number">3</span>);</span><br><span class="line">		&#125;)();  <span class="comment">//匿名函数自调用</span></span><br><span class="line">		<span class="keyword">var</span> a = <span class="number">4</span>;</span><br><span class="line">		<span class="built_in">console</span>.log(a);</span><br><span class="line">		</span><br><span class="line">		</span><br><span class="line">		(<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">			<span class="keyword">var</span> a = <span class="number">1</span>;</span><br><span class="line">			<span class="function"><span class="keyword">function</span> <span class="title">test</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">				<span class="built_in">console</span>.log(++a);</span><br><span class="line">			&#125;</span><br><span class="line">			<span class="built_in">window</span>.$ = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;   <span class="comment">//向外暴露一个全局函数</span></span><br><span class="line">				<span class="keyword">return</span> &#123;</span><br><span class="line">					test: test</span><br><span class="line">				&#125;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;)();</span><br><span class="line">		$().test();  <span class="comment">//$是一个函数，$执行后返回一个对象，对象有test这个方法</span></span><br><span class="line">	&lt;<span class="regexp">/script&gt;</span></span><br></pre></td></tr></table></figure>
<p>this<br>this是什么？<br>任何函数本质上都是通过某个对象来调用的，如果没有指定就是window<br>所有函数内部都有一个变量this<br>它的值是调用函数的当前对象</p>
<p>如何确定this的值？<br>this只有在函数调用的时候才会发生绑定，谁调用的这个函数，函数中的this就指向谁<br>好了，我的分享就到这里了，谢谢大家</p>

      
      <!-- reward -->
      
      <div id="reward-btn">
        打赏
      </div>
      
    </div>
    
    
      <!-- copyright -->
      
        <div class="declare">
          <ul class="post-copyright">
            <li>
              <i class="ri-copyright-line"></i>
              <strong>版权声明： </strong s>
              本博客所有文章除特别声明外，均采用 <a href="https://www.apache.org/licenses/LICENSE-2.0.html" rel="external nofollow"
                target="_blank">Apache License 2.0</a> 许可协议。转载请注明出处！
            </li>
          </ul>
        </div>
        
    <footer class="article-footer">
      
          
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=https://lockme.gitee.io/2020/06/13/Advanced-JS-one-md/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>
      
      

    </footer>

  </div>

  
  
  <nav class="article-nav">
    
      <a href="/2020/06/13/Advanced-JS-two-md/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            Advanced_JS_two.md
          
        </div>
      </a>
    
    
      <a href="/2020/05/14/Less-md/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">Less.md</div>
      </a>
    
  </nav>


  

  
  
<!-- valine评论 -->
<div id="vcomments-box">
    <div id="vcomments">
    </div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src='https://cdn.jsdelivr.net/npm/valine@1.3.10/dist/Valine.min.js'></script>
<script>
    new Valine({
        el: '#vcomments',
        app_id: 'pmaQYnbUE9O0H1hiYKLiec4R-gzGzoHsz',
        app_key: 'LMujtI79W4vgEQ3Az5IMo50y',
        path: window.location.pathname,
        notify: 'false',
        verify: 'false',
        avatar: 'mp',
        placeholder: '给我的文章加点评论吧~',
        recordIP: true
    });
    const infoEle = document.querySelector('#vcomments .info');
    if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
        infoEle.childNodes.forEach(function (item) {
            item.parentNode.removeChild(item);
        });
    }
</script>
<style>
    #vcomments-box {
        padding: 5px 30px;
    }

    @media screen and (max-width: 800px) {
        #vcomments-box {
            padding: 5px 0px;
        }
    }

    #vcomments-box #vcomments {
        background-color: #fff;
    }

    .v .vlist .vcard .vh {
        padding-right: 20px;
    }

    .v .vlist .vcard {
        padding-left: 10px;
    }
</style>

  

  
  
  

</article>
</section>
      <footer class="footer">
  <div class="outer">
    <ul class="list-inline">
      <li>
        &copy;
        2020
        月下ctrlc
      </li>
      <li>
        
        Powered by
        
        
        <a href="https://hexo.io" target="_blank">Hexo</a> Theme <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
        
      </li>
    </ul>
    <ul class="list-inline">
      <li>
        
        
        <span>
  <i>PV:<span id="busuanzi_value_page_pv"></span></i>
  <i>UV:<span id="busuanzi_value_site_uv"></span></i>
</span>
        
      </li>
      
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278069914&amp;web_id=1278069914'></script>
        
      </li>
    </ul>
  </div>
</footer>
      <div class="to_top">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>
      </div>
    </main>
    <aside class="sidebar">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/avatar.jpg" alt="Small Bridge"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags/Vue/">Vue</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="http://shenyu-vip.lofter.com" target="_blank" rel="noopener">主题作者相册</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/2020/03/18/about">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="Search">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>拿钱砸死我吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="/images/alipay.png">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="/images/wechat.png">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
    
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/share.js"></script>


<script src="/js/lazyload.min.js"></script>


<script>
  try {
    var typed = new Typed("#subtitle", {
      strings: ['面朝大海，春暖花开', '愿你一生努力，一生被爱', '想要的都拥有，得不到的都释怀'],
      startDelay: 0,
      typeSpeed: 200,
      loop: true,
      backSpeed: 100,
      showCursor: true
    });
  } catch (err) {
  }

</script>




<script src="/js/tocbot.min.js"></script>

<script>
  // Tocbot_v4.7.0  http://tscanlin.github.io/tocbot/
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: 'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto',
    onClick: (e) => {
      $('.toc-link').removeClass('is-active-link');
      $(`a[href=${e.target.hash}]`).addClass('is-active-link');
      $(e.target.hash).scrollIntoView();
      return false;
    }
  });
</script>



<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/js/ayer.js"></script>



<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>


<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
      tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
  });

  MathJax.Hub.Queue(function() {
      var all = MathJax.Hub.getAllJax(), i;
      for(i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
      }
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/mathjax@2.7.6/unpacked/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script>
  var ayerConfig = {
    mathjax: true
  }
</script>



<script src="/js/busuanzi-2.3.pure.min.js"></script>



<script type="text/javascript" src="https://js.users.51.la/20544303.js"></script>


    
  </div>
</body>

</html>